package com.zhuoshi.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.zhuoshi.bean.WdPayType;
import com.zhuoshi.bean.WdUser;
import com.zhuoshi.service.WdPayTypeService;
import com.zhuoshi.serviceImpl.WdPayTypeServiceImpl;
import com.zhuoshi.serviceImpl.WdUserServiceImpl;
@Controller
public class WdPayTypeController {
	@Autowired
	private WdPayTypeServiceImpl wdPayTypeServiceImpl;
	
	
	@RequestMapping("/getAllPayType")
	public String Test(Model model,HttpServletRequest request)
	{
		
		List<WdPayType> wdpaytype = wdPayTypeServiceImpl .findAll(); 
		model.addAttribute("wdpaytype",wdpaytype );
		request.setAttribute("wdpaytype",wdpaytype );
		//System.out.println(user.getUpdateTime());
		return "/Fukuan";  
	}
	 @RequestMapping("/toAddPayType")  
	    public String toAddPayType(){  
	        return "/addPayType";  
	    } 
	
	@RequestMapping("/addPayType")  
    public String addPayType(WdPayType wdpaytype,Model model){  
		wdPayTypeServiceImpl.save(wdpaytype);  
        return "redirect:/getAllPayType";  
    } 
	
	
	
	
	  
	
	 @RequestMapping("/toupdatePayType")  
	    public String getUser(String pay_type_id,HttpServletRequest request,Model model){  
	       request.setAttribute("userr", wdPayTypeServiceImpl.findById( pay_type_id));  
	       System.out.println(wdPayTypeServiceImpl.findById( pay_type_id).getPay_type_id()+"aaaaa");
	       // model.addAttribute("userr", wdPayTypeServiceImpl.findById( pay_type_id));  
	        return "/updatePayType";
	 }
	
	
	
	
	
    @RequestMapping("/updatePayType")  
    public String updatePayType(WdPayType wdpaytype,HttpServletRequest request,Model model){  
       if(wdPayTypeServiceImpl.update(wdpaytype)){  
    	wdpaytype= wdPayTypeServiceImpl.findById(wdpaytype.getPay_type_id());  
            request.setAttribute("wdpaytype", wdpaytype);  
            model.addAttribute("wdpaytype", wdpaytype);  
           return "redirect:/getAllPayType";  
        }else{  
           return "/error";  
        }  
    } 
    @RequestMapping("/delUser")  
    public String delUser(String pay_type_id,HttpServletRequest request,HttpServletResponse response){  
          
        wdPayTypeServiceImpl.delete(pay_type_id); 
        return "redirect:/getAllPayType";
             
        }  
         
         
      
} 
    
    
	

